import axios from 'axios';
// import store from '@/store'

// create an axios instance
const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API, // api的base_url
    withCredentials: true,
    headers: { 'Content-Type': 'application/json' },
    responseType: 'json',
    timeout: 500000 // request timeout
});

service.interceptors.request.use(config => {
    // Do something before request is sent
    // if (store.getters.token) {
    //   config.headers['X-Token'] = getToken() // 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改
    // }
    config.params = Object.assign(config.params || {}, { 'access_token': '1234' });
    return config;
}, error => {
    // Do something with request error
    Promise.reject(error);
});

// response interceptor restful风格返回数据200 就必须是正确的返回
service.interceptors.response.use(
    response => {
        return response.data;
    },
    error => {
        return Promise.reject(error.response);
    });

export default service;
